﻿using UnityEngine;
using UnityEditor;
using System.IO;

public class RefreshConfig
{
    public static readonly string EXCEL_FOLDER = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + "ExcelConfigs/";
    public static readonly string CONFIG_FOLDER = Application.dataPath + "/Resources/Configs/";

    [MenuItem("Assets/RefreshConfig")]
    public static void MakeFolderPackageToFolderSamePath()
    {
        var activeObject = Selection.activeObject;
        var assetPath = AssetDatabase.GetAssetPath(activeObject);
        if (!string.IsNullOrEmpty(assetPath) && !Path.HasExtension(assetPath))
        {
            if (assetPath.Length < 30) return;
            string strPath = assetPath.Substring(25, assetPath.Length - 25);

            ExcelToolKit.Excel2JsonFile(EXCEL_FOLDER + strPath + "/part_conf.xlsx", CONFIG_FOLDER + strPath + "/part_conf.json");
            ExcelToolKit.Excel2JsonFile(EXCEL_FOLDER + strPath + "/prop_conf.xlsx", CONFIG_FOLDER + strPath + "/prop_conf.json");
            ExcelToolKit.Excel2JsonFile(EXCEL_FOLDER + strPath + "/task_conf.xlsx", CONFIG_FOLDER + strPath + "/task_conf.json");
            ExcelToolKit.Excel2JsonFile(EXCEL_FOLDER + strPath + "/voice.xlsx", CONFIG_FOLDER + strPath + "/voice.json");
            Debug.Log(EXCEL_FOLDER + strPath);
        }
        else
        {
            //if (assetPath.Length < 30) return;
            string strPath = assetPath.Substring(25, assetPath.Length - 30);
            Debug.Log("文件 = " + assetPath);
            Debug.Log(EXCEL_FOLDER + strPath + ".xlsx");
            Debug.Log(CONFIG_FOLDER + strPath + ".json");

            ExcelToolKit.Excel2JsonFile(EXCEL_FOLDER + strPath + ".xlsx", CONFIG_FOLDER + strPath + ".json");
        }
    }
}
